package com.reran.geek.demo.Week02;

import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

import java.io.IOException;

/**
 * @description:
 * @author: WangSiTeng
 * @date: 2021/11/14
 */
public class OkHttpUtil {

    public static void main(String[] args) throws IOException {

        String url = "http://localhost:8801";
//        String url = "http://www.baidu.com";
        String responseString = OkGet(url);
        System.out.println("OkHttpUtil call " + url + " response: " + responseString);

    }

    public static String OkGet(String url) throws IOException {
        OkHttpClient client = new OkHttpClient();

        Request request = new Request.Builder()
                .url(url)
                .build();

        try (Response execute = client.newCall(request).execute();) {
            return execute.body().toString();
        }
    }
}
